<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="db.Album"%>
<%@page import="presentation.PresentationsBean"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.text.SimpleDateFormat"%><html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@page import="presentation.Get16ImagesBean"%>
<%@page import="java.util.List"%>
<%@page import="db.Comment"%> 
<%@page import="db.Picture"%> 
<head>
	<link rel="stylesheet" type="text/css" href="css/styleGallery.css" /> 
	<link rel="stylesheet" type="text/css" href="css/ViewPicture.css" />   
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script language="javascript">
	function testcon(){
		var df = prompt(" Enter your comment");
		document.comment.content.value = df;
		}
	</script>
	<title>Снимка</title>
</head>
<%  
	
	Integer i = null;
	Object o = session.getAttribute("pageNum");
	if (o != null) {
		i = (Integer)o;
	} else {
		%>
		<c:redirect url="Home.jsp" > </c:redirect>
		<%
	}
	Get16ImagesBean b = new Get16ImagesBean(i, null);  
%>
<body id="bd">
	<div id="container">
		<my:header/>
		<% SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
		if (session.getAttribute("user")==null){ %>
		<my:menulogout/>
		<%}else{ 
		 List<Album> albums= b.getUserAlbums( (Long)session.getAttribute("userid"));%>
		
	<my:menulogin/>
		<%} %>
		
   		<div id="midcontainer">
   			<p id="text" ><%=b.getPicturePath(Long.parseLong(request.getParameter("image"))) %></p>
   			<div id ="arrow">
             <br><br><br><br><br><br><br><br><br><br><br>	
             <%if((Long)session.getAttribute("startPic")==Long.parseLong(request.getParameter("image"))){		
   					%><!-- <img  src="img/right_symbol1.png"/> --><% 
   					}else{%>	
         	            <a href="PrevPageServlet?image=<%=Long.parseLong(request.getParameter("image"))%>&page=<%=session.getAttribute("pageNum")%>"><img  src="img/right_symbol1.png"/> </a>  
   				    <%}%>
     		</div>
      		
      		<div id="picture">	
        		<div style="text-align:center;">
         			<div class="shadow2">     
         				 <a title="кликни за да видиш оригиналния размер" href="Image?image=<%=request.getParameter("image")%>" target="_blank"><img  src="Image?image=<%=request.getParameter("image")%>&size=m"/> </a>
         			</div>
       		    </div> 	
     	    </div>  
     	 
        	<div id ="arrow">
              <br><br><br><br><br><br><br><br><br><br><br> 
         	          <%  if(((Long)session.getAttribute("endPic")!=null)&&((Long)session.getAttribute("endPic")==Long.parseLong(request.getParameter("image")))){		
   					%><!-- <img  src="img/left_symbol1.png"/> --><% 
   					}else{%>	
         	            <a href="NextPageServlet?image=<%=Long.parseLong(request.getParameter("image"))%>&page=<%=session.getAttribute("pageNum")%>"><img  src="img/left_symbol1.png"/> </a>
   				    <%}%>
     		</div>
            	
            <%long picId=Long.parseLong(request.getParameter("image"));%>
       	    <%if (session.getAttribute("user")!=null){ %>
          	 	
          	<div class="icon">
          	<div class="icon">
          	<%if(b.isUserPicture((String)session.getAttribute("user"),picId)){ %>
         	 	  <li><a title="изтрий" href="DeletePictureServlet?image=<%=picId %>"><img src="img/trash2.png"/></a></li>
      			  <li><a title="редактирай" href="EditPictureServlet?image=<%=picId %>"><img  src="img/photo1.png"/></a></li>
      			   <%} %>
      		 	  <!-- <li><a title="прикачи към файл" href="#"><img  src="img/mail1.png"/></a></li> -->
          	</div>     
          	</div>
          	<%} %>

		    <% List<Comment> comments =b.getCommentsByPicture(picId); %>
           <%if (session.getAttribute("user")==null){%>
		  <br>
			<div class="comment">
				<table cellpadding="2" cellspacing="0">
  					<col width="60"><col width="580">
       					 <tbody>
       					 <%
       					 for(Comment comm:comments){%>
       					 <tr>
           					 <td class="description" valign="top" width="80"> <%=comm.getUser().getUserName() %>
           					 </td>
           					 <td class="description" valign="top" width="650"><%=comm.getCommentContent() %></td>
        				</tr>
        				<%} %>
   				 </tbody></table>
    		</div>	
		<%}else{ %>
			<div class="addcomment">
  				<b>Добави коментар<b> 
  				<form action="AddCommentServlet?image=<%=picId%>" method="post">
                <input class="box" name="content" size="95" type="text">
                <input class="button" value="Добави" type="submit">
                </form>
		    </div>
    
			<div class="comment">
				<table cellpadding="2" cellspacing="0">
  					<col width="10"><col width="80"><col width="490">
       					 <tbody>
       					 <%
       					 for(Comment comm:comments){%>
       					 <tr>
           				 	<td class="edit" nowrap="nowrap" valign="top" width="40" >  
           				 	
         					<%if(b.isUserPicture((String)session.getAttribute("user"),picId)){ %>
         					 	   <%if (b.isUserComment((Long)session.getAttribute("userid"),comm.getCommentId())){ %>
         					 	   <div class="iconcomm">
         					 	     <li><a title="редактирай" href="EditCommentServlet?image=<%=picId%>&commId=<%= comm.getCommentId()%>"><img src="img/edit1.png"/></a></li>
         					 	     </div>
         					 	     <div class="iconcomm">
         					 	  <li> <a title="изтрий" href="DeleteCommentServlet?image=<%=Long.parseLong(request.getParameter("image"))%>&commId=<%=comm.getCommentId()%>"><img src="img/trash3.png"/></a></li>
         					 		</div>
         					 	 <%}else{ %>
         					 	  <div class="iconcomm">
         					 	  <li><a title="изтрий" href="DeleteCommentServlet?image=<%=Long.parseLong(request.getParameter("image"))%>&commId=<%=comm.getCommentId()%>"><img src="img/trash3.png"/></a></li>
         					 	   </div>
         					 	   <%} %>
           				 	<%}else{
           				 		if (b.isUserComment((Long)session.getAttribute("userid"),comm.getCommentId())){ %>
           				 		<div class="iconcomm">
           				           <li><a title="редактирай" href="EditCommentServlet?image=<%=picId%>&commId=<%= comm.getCommentId()%>"><img src="img/edit1.png"/></a></li>
           				        </div>
           				        <div class="iconcomm">
           				 	      <li>  
           				 	      <a title="изтрий" href="DeleteCommentServlet?image=<%=Long.parseLong(request.getParameter("image"))%>&commId=<%=comm.getCommentId()%>"><img src="img/trash3.png"/></a></li>
           				 	  </div>
           				 	   <%}%>
           				 	<%} %>
           				 	 </td>   
           				 	
           					 <td class="description" valign="top" width="150"> <%=comm.getUser().getUserName() %><br/> <span class="date"><%=sdf.format(comm.getCommentDate()) %></span></td>
           					 <td class="description" valign="top" width="450"><%=comm.getCommentContent() %></td>
        				</tr>
        				<%} %> 				
    </tbody></table>
</div>
		<%} %>   
		

</div><!-- midcontainer -->
<%b.releaseResources(); %>
<my:footer/>
	
</body>
</html>